package com.sia.springcloud.controller;


import com.sia.springcloud.service.IDeviceService;
import com.sia.springcloud.service.IFileParseService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * <p>
 * 通信协议设备表 前端控制器
 * </p>
 *
 * @author Sirius
 * @since 2021-12-27
 * 说明：
 * 增删改返回的都是一个SimpleResult，包含一个result和message
 * 查询返回的是一个GridDataResult，包含一个total和root
 */
@Slf4j
@RestController
@RequestMapping("//deviceController")
public class DeviceController {

    @Resource
    private IFileParseService fileParseService;

    @Resource
    private IDeviceService deviceService;


    /**
     * 添加设备
     *
     * @param request protocolName和一个deviceId
     * @return
     */
    @RequestMapping("/insertDevice")
    public String insertDevice(HttpServletRequest request) {
        log.info("插入设备");
        return deviceService.insertDevice(request);

    }


    /**
     * 分页查询设备 只需要一个protocolName
     *
     * @param request protocolName和start、limit
     * @return
     */
    @RequestMapping("/queryDevice")
    public String queryDevice(HttpServletRequest request) {
        log.info("查询设备");
        return deviceService.queryDevice(request);
    }

    /**
     * 删除设备
     *
     * @param request protocolName和一个deviceId
     * @return
     */
    @RequestMapping("/deleteDevice")
    public String deleteDevice(HttpServletRequest request) {
        log.info("删除设备");
        return deviceService.deleteDevice(request);
    }


    /**
     * 修改设备
     *
     * @param request protocolName和对应协议的设备信息
     * @return
     */
    @RequestMapping("/updateDevice")
    public String updateDevice(HttpServletRequest request) {
        log.info("更新设备");
        return deviceService.updateDevice(request);
    }


    /**
     * 获取设备表单格式
     *
     * @param request
     * @return
     */
    @RequestMapping("/tableStructure")
    public String tableStructure(HttpServletRequest request) {
        log.info("获取设备表结构");
        return deviceService.tableStructure(request);
    }


}
